import {
  userInfo,
  orderList,
  orderTips
} from '../../apis/user';
import {
  splicing,
  handleDate
} from '../../utils/util';
const app = getApp();

Page({
  data: {
    myEnroll: [{
      name: '待审核',
      icon: '/images/personal_examine.png',
      url: '/pages/mySignUp/index?navIndex=1'
    }, {
      name: '待支付',
      icon: '/images/personal_payment.png',
      url: '/pages/mySignUp/index?navIndex=2'
    }, {
      name: '待参加',
      icon: '/images/personal_join.png',
      url: '/pages/mySignUp/index?navIndex=3'
    }, {
      name: '已完成',
      icon: '/images/personal_complete.png',
      url: '/pages/mySignUp/index?navIndex=4'
    }],
    otherActions: [{
      name: '我的活动码',
      icon: '/images/personal_myCode.png',
      url: 'myCode',
      show: true
    }, {
      name: '我的收藏',
      icon: '/images/personal_myCollect.png',
      url: '/pages/myCollect/index',
      show: true
    }, {
      name: '联系协会',
      icon: '/images/personal_contact.png',
      url: '/pages/customerService/index',
      show: true
    }, {
      name: '协会管理员',
      icon: '/images/personal_admin.png',
      url: '/pages/writeOff/index',
      show: false
    },
    {
        name: '我的视频',
        icon: '/images/personal_video.png',
        url: '/pages/trainingVideo/myCollectV/index',
        spicon:'video',
        show: true,
    },
    {
        name: '我的资料',
        icon: '/images/personal_paper.png',
        url: '/pages/trainingVideo/myCollectC/index',
        spicon:'information',
        show: true
    },
    
],
    userInfo: {},
    myCodeList: [],
    myCodeShow: false,
    tips: {}
  },

  onLoad() {

  },

  onShareAppMessage() {
    return {
      title: '北京市移民及出入境服务行业协会',
      path: '/pages/start/index',
      imageUrl: '/images/logo.png'
    }
  },

  onShow() {
    this.getUserInfo();
    this.getMyCode();
    this.getTips();
  },

  // 获取用户信息
  getUserInfo() {
    userInfo().then(res => {
      if (res.data.code === 200) {
        let {
          user
        } = res.data.data;
        user.username = user.username ? user.username : app.globalData.userInfo.nickName;
        user.avatar = user.avatar ? user.avatar : app.globalData.userInfo.avatarUrl;
        this.setData({
          userInfo: user,
          ['otherActions[3].show']: new RegExp('verifier').test(user.roles)
        });
      };
    });
  },

  // 获取我的活动
  getMyCode() {
    orderList(4).then(res => {
      if (res.data.code === 200) {
        let {
          rows
        } = res.data;
        rows.forEach(v => {
          v.orderDetail.imageList = v.orderDetail.imageList.map(val => val = splicing(val));
          v.orderDetail.startTime = handleDate(v.orderDetail.startTime);
          v.orderDetail.closeTime = handleDate(v.orderDetail.closeTime);
        });
        this.setData({
          myCodeList: rows
        });
      };
    });
  },
  // 获取红点提示
  getTips() {
    orderTips().then(res => {
      if (res.data.code === 200) {
        let {
          data
        } = res.data;
        this.setData({
          tips: data
        });
      };
    });
  },

  // 编辑
  editUserInfo() {
    wx.navigateTo({
      url: '/pages/bindPhone/index?type=user'
    });
  },

  myEnrollJump(e) {
    let {
      url
    } = e.currentTarget.dataset;
    if (url === 'myCode') {
      this.setData({
        myCodeShow: true
      });
    } else {
      wx.navigateTo({
        url: url
      });
    };
  },

  hideOverlay() {
    this.setData({
      myCodeShow: false
    });
  }
})